import boto3
from botocore.exceptions import NoCredentialsError
import asyncio


# 替换以下参数为您的实际信息
local_file_path = 'your_local_file.txt'
bucket_name = 'your_s3_bucket_name'
s3_file_name = 'your_s3_file_name.txt'


async def main():
    aws_access_key_id = 'your_access_key_id'
    aws_secret_access_key = 'your_secret_access_key'
    aws_region = 'your_region'

    # 创建 S3 客户端
    s3 = boto3.client('s3', aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key,
                      region_name=aws_region)

    try:
        # 上传文件
        s3.upload_file(local_file_path, bucket_name, s3_file_name)
        print(f"File {s3_file_name} uploaded successfully to {bucket_name}")
    except FileNotFoundError:
        print(f"The file {local_file_path} was not found.")
    except NoCredentialsError:
        print("Credentials not available or incorrect.")



if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())